package com.nt.train.service.context;
import com.nt.train.enums.GroupType;
import com.nt.train.service.IGroupSelect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
/**
 * 人群选择工厂类
 * @author hlf
 * @version 1.0
 * @date 2022/8/5 14:25
 */
@Service
public class GroupSelectFactory {

    @Autowired
    private List<IGroupSelect> groupSelectList;

    /**
     * 根据人群类型选择具体的实现类
     * @param type 人群类型
     * @return 人群选择具体实现类
     */
    public IGroupSelect getGroupSelect(GroupType type) {
        Optional<IGroupSelect> groupSelectOptional = groupSelectList.stream()
                .filter(t -> t.type() == type).findAny();
        return groupSelectOptional.orElseThrow(() -> new IllegalArgumentException("暂不支持该人群方式"));
    }
}